package com.mlf.abstractFactory.spring.ui;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


@Service
public class ThemeService {
    private final Map<String, ThemeFactory> themeFactories;

    // 自动注入所有ThemeFactory实现
    @Autowired
    public ThemeService(Map<String, ThemeFactory> themeFactories) {
        this.themeFactories = themeFactories;
    }

    // 根据主题名称获取工厂
    public ThemeFactory getThemeFactory(String themeName) {
        ThemeFactory factory = themeFactories.get(themeName);
        if (factory == null) {
            throw new IllegalArgumentException("Invalid theme: " + themeName);
        }
        return factory;
    }

    // 获取可用主题列表
    public List<String> getAvailableThemes() {
        return new ArrayList<>(themeFactories.keySet());
    }

}
